package com.sun.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletedFutureExample {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建一个已经完成的CompletableFuture
        CompletableFuture<String> completedFuture = CompletableFuture.completedFuture("立即完成的结果");

        // 直接获取结果，不会阻塞
        System.out.println("结果: " + completedFuture.get());

        // 检查是否已完成
        System.out.println("是否已完成: " + completedFuture.isDone());
        System.out.println("是否有异常: " + completedFuture.isCompletedExceptionally());
    }
}
